import { roleInfo } from '@/api/index'
import { getToken, setToken, removeToken } from '@/utils/auth'

export default {
  namespaced: true,
  state () {
    return {
      token: getToken(),
      roleList: {},
      areaCode:"",
      roleId: ""
    }
  },
  mutations: {
    setToken(state, payload) {
      state.token = payload.access_token
      state.areaCode = payload.area_code
      state.roleId = payload.role_id
      setToken(payload.access_token)
    },
    delToken (state) {
      state.token = null
      removeToken()
    },
    storeRoleList (state, payload) {
      state.roleList = payload
    }

    // updateRoutes (state, payload) {
    //   state.routes = [...constantRoutes, ...payload]
    // }
  },
  actions: {
    async roleListFunction(context, payload) {
 
      const res = await roleInfo({ id: payload })
  
      context.commit('storeRoleList', res.data)
    }
  }
}
